import '../../config/address.dart';

class GameLinkageModel {
  GameLinkageModel({
    this.list,
    this.cardList,
    this.activityDetail,
  });

  GameLinkageModel.fromJson(dynamic json) {
    if (json['list'] != null) {
      list = [];
      json['list'].forEach((v) {
        list?.add(GLCList.fromJson(v));
      });
    }
    if (json['cardList'] != null) {
      cardList = [];
      json['cardList'].forEach((v) {
        cardList?.add(GLCCardListItem.fromJson(v));
      });
    }
    activityDetail = json['activityDetail'] != null ? ActivityDetail.fromJson(json['activityDetail']) : null;
  }

  List<GLCList>? list;
  List<GLCCardListItem>? cardList;
  ActivityDetail? activityDetail;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    if (list != null) {
      map['list'] = list?.map((v) => v.toJson()).toList();
    }
    if (cardList != null) {
      map['cardList'] = cardList?.map((v) => v.toJson()).toList();
    }
    if (activityDetail != null) {
      map['activityDetail'] = activityDetail?.toJson();
    }
    return map;
  }
}

class ActivityDetail {
  ActivityDetail({
    this.startTime,
    this.endTime,
    this.activityTime,
    this.status,
  });

  ActivityDetail.fromJson(dynamic json) {
    startTime = json['startTime'];
    endTime = json['endTime'];
    activityTime = json['activityTime'];
    status = json['status'];
  }

  String? startTime;
  String? endTime;
  String? activityTime;
  num? status;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['startTime'] = startTime;
    map['endTime'] = endTime;
    map['activityTime'] = activityTime;
    map['status'] = status;
    return map;
  }
}

class GLCCardListItem {
  GLCCardListItem({
    this.productID,
    this.productName,
    this.desc,
    this.type,
    this.sendGame,
    this.bgImg,
    this.originalPrice,
    this.discountedPrice,
    this.discountedPriceIos,
    this.discountedPriceAnd,
    this.position,
    this.privilege,
  });

  GLCCardListItem.fromJson(dynamic json) {
    productID = json['productID'];
    productName = json['productName'];
    desc = json['desc'];
    type = json['type'];
    sendGame = json['sendGame'];
    isPay = json['isPay'];
    bgImg = json['bgImg'];
    originalPrice = json['originalPrice'];
    discountedPrice = json['discountedPrice'];
    discountedPriceIos = json['discountedPriceIos'];
    discountedPriceAnd = json['discountedPriceAnd'];
    position = json['position'];
    gameCode = json['gameCode'] != null ? json['gameCode'].cast<String>() : [];
    privilege = json['privilege'] != null ? json['privilege'].cast<num>() : [];
    if (json['newPrivilege'] != null) {
      newPrivilege = [];
      json['newPrivilege'].forEach((v) {
        newPrivilege?.add(Privilege.fromMap(v));
      });
    }
  }

  String? productID;
  String? productName;
  String? desc;
  num? type;
  bool? sendGame;
  List<String>? gameCode;
  bool? isPay;
  String? bgImg;
  int? originalPrice;
  int? discountedPrice;
  int? discountedPriceIos;
  int? discountedPriceAnd;
  String? position;
  List<int>? privilege;
  List<Privilege>? newPrivilege;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['productID'] = productID;
    map['productName'] = productName;
    map['desc'] = desc;
    map['type'] = type;
    map['sendGame'] = sendGame;
    map['bgImg'] = bgImg;
    map['originalPrice'] = originalPrice;
    map['discountedPrice'] = discountedPrice;
    map['discountedPriceIos'] = discountedPriceIos;
    map['discountedPriceAnd'] = discountedPriceAnd;
    map['position'] = position;
    // map['privilege'] = privilege;
    // map['newPrivilege'] = newPrivilege;
    return map;
  }
}

class GLCList {
  GLCList({
    this.name,
    this.url,
    this.cover,
    this.sourceURL,
    this.type,
  });

  GLCList.fromJson(dynamic json) {
    name = json['name'];
    url = json['url'];
    cover = json['cover'];
    sourceURL = json['sourceURL'];
    type = json['type'];
  }

  String? name;
  String? url;
  String? cover;
  String? sourceURL;
  num? type;
  String get realVideoUrl {
    return "${Address.baseApiPath}/vid/h5/m3u8/$sourceURL?token=${Address.token}&c=${Address.cdnAddress}";
    // return '${Address.baseHost}${Address.API_PREFIX}${Address.VIDEO_SUFFIX}/$sourceURL?Authorization=${Address.token}';
  }
  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['name'] = name;
    map['url'] = url;
    map['cover'] = cover;
    map['sourceURL'] = sourceURL;
    map['type'] = type;
    return map;
  }
}

///特权信息
class Privilege {
  String? img;
  String? privilegeName;
  String? privilegeDesc;

  static Privilege fromMap(Map<String, dynamic> map) {
    Privilege privilege = Privilege();
    privilege.img = map['img'];
    privilege.privilegeName = map['privilegeName'];
    privilege.privilegeDesc = map['privilegeDesc'];
    return privilege;
  }

  Map toJson() => {
    "img": img,
    "privilegeName": privilegeName,
    "privilegeDesc": privilegeDesc,
  };
}